<include file="./Template/Admin/header.html" title="添加单页" />
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加单页</h5>
                </div>
                <div class="ibox-content">
                    <div class="row m-b-sm m-t-sm">
                        <div class="col-md-2">
                            <a href="{:U('Admin/Page/index')}" class="btn btn-outline btn-primary">返回单页列表</a>
                        </div>
                    </div>
                    <form class="form-horizontal m-t" id="Forma" enctype="multipart/form-data" action="{:U('Admin/Page/Save')}">
                        <input type="hidden" name="id" value="{$pageInfo.id}" />
                        <div class="form-group">
                            <label class="col-sm-2 control-label">单页名称</label>
                            <div class="col-sm-10">
                                <input type="text" name="title" id="title" value="{$pageInfo.title}" class="form-control">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">英文目录</label>
                            <div class="col-sm-10">
                                <input type="text" name="name" id="name" value="{$pageInfo.name}" class="form-control">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">内容</label>
                            <div class="col-sm-10">
                                <!-- 加载编辑器的容器 -->
                                <script id="content" name="content" type="text/plain">{$pageInfo.content}</script>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">关键词</label>
                            <div class="col-sm-10">
                                <input type="text" name="keyword" id="keyword" value="{$pageInfo.keyword}" class="form-control">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">描述</label>

                            <div class="col-sm-10">
                                <input type="text" name="description" id="description" value="{$pageInfo.description}" class="form-control">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">外链接</label>

                            <div class="col-sm-10">
                                <input type="text" value="{$pageInfo.link}" name="link" id="link" class="js-switch">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">排序</label>
                            <div class="col-sm-10">
                                <input type="text" value="{$pageInfo.sort}" name="sort" id="sort" class="js-switch">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button class="btn btn-primary" type="submit">保存</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>



<script src="__ADMIN__js/jquery.min.js"></script>
<script src="__ADMIN__js/bootstrap.min.js"></script>
<script src="__ADMIN__js/plugins/layer.3/layer.js"></script>
<script src="__ADMIN__js/common.js"></script>
<script src="__ADMIN__js/content.min.js"></script>
<script src="__ADMIN__js/plugins/validate/jquery.validate.min.js"></script>
<script src="__ADMIN__js/plugins/validate/messages_zh.min.js"></script>
<script src="__ADMIN__js/plugins/switchery/switchery.js"></script>

<script type="text/javascript" src="__ADMIN__plugins/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__ADMIN__plugins/ueditor/ueditor.all.js"></script>

<script>
    var elem = document.querySelector('.js-switch');
    var init = new Switchery(elem);

    var ue = UE.getEditor('content');

    $(function(){
        $.validator.setDefaults({
            highlight: function (e) {
                $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
            }, success: function (e) {
                e.closest(".form-group").removeClass("has-error").addClass("has-success")
            }, errorElement: "span", errorPlacement: function (e, r) {
                e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
            }, errorClass: "help-block m-b-none", validClass: "help-block m-b-none"
        }), $().ready(function () {
            var e = "<i class='fa fa-times-circle'></i> ";

            $("#Forma").validate({
                rules: {
                    title: "required",
                    name:"required",
                    content: "required",
                    keyword: "required",
                    description: "required",
                    link:"required",
                    sort: "required"
                },
                messages: {
                    title: e + "请输入单页标题",
                    name: e + "请输入单页英文名称",
                    content: e + "请输入单页内容",
                    keyword: e + "请输入单页的关键词",
                    description: e + "请输入单页的描述",
                    link: e + "请输入单页的排序",
                    sort: e + "请输入单页的排序"
                },
                submitHandler: function(form){
                    var data = new  FormData(document.getElementById('Forma'));
                    $.ajax({
                        url:$(form).attr('action'),
                        type:"POST",
                        data:data,
                        cache: false,
                        processData:false,
                        contentType:false,
                        success:function(data){
                            if(data.status > 0){
                                common.error(data.msg);
                            }else{
                                common.success(data.msg,"{:U('Admin/Page/index')}");
                            }
                        },
                        dataType:'JSON'
                    });
                    return false;
                }
            });
        });
    });
</script>
</body>
</html>
